﻿using System;
using System.Text;

namespace Kay.Test.Udp
{
    public class UdpData
    {
        public string Id32 { get; set; }

        public int Count10 { get; set; }

        public int Index10 { get; set; }

        public int Size10 { get; set; }

        public string EndPoint21 { get; set; }

        public string ToEndPoint21 { get; set; }

        public int Length = 32 + 10 * 3 + 21 * 2;

        public string Text { get; set; }

        public UdpData() { }

        public UdpData(int count, int size, string end, string toEnd)
        {
            Id32 = Guid.NewGuid().ToString("N");
            Count10 = count;
            Index10 = 0;
            Size10 = size;
            EndPoint21 = end;
            ToEndPoint21 = toEnd;
        }

        public byte[] GetBytes(Encoding encoding)
        {
            var str = string.Format("{0}{1}{2}{3}{4}{5}", Id32, Count10.ToString().PadLeft(10, '0'),
                Index10.ToString().PadLeft(10, '0'), Size10.ToString().PadLeft(10, '0'),
                EndPoint21.PadRight(21, char.MinValue), ToEndPoint21.PadRight(21, char.MinValue));
            return encoding.GetBytes(str);
        }
    }
}